<template>
  <div class="right-panel" :class="{ active: isActive }">
    <!-- 遮罩层 -->
    <div v-if="isActive" class="mask" @click.self="hidePanel"></div>

    <!-- 面板内容容器 -->
    <div class="panel-content" :style="{ width: panelWidth + 'px' }">
      <!-- 动态组件 -->
      <component :is="currentComponent" v-if="isActive" />
      <!-- 关闭按钮 -->
      <el-button class="close-btn" circle @click="hidePanel">
        <el-icon><Close /></el-icon>
      </el-button>
    </div>
  </div>
</template>

<script setup lang="ts">
import { defineProps, defineEmits, ref } from 'vue'
import { Close } from '@element-plus/icons-vue'

// 接收参数
const props = defineProps<{
  currentComponent: any
  isActive: boolean
  panelWidth?: number
}>()

// 发送事件
const emit = defineEmits(['close'])

// 隐藏面板
const hidePanel = () => {
  emit('close')
}
</script>

<style scoped>
.right-panel {
  position: absolute;
  top: 0;
  right: 50px; /* 与右侧按钮区对齐 */
  height: 100%;
  z-index: 999;
  transition: transform 0.3s ease-in-out;
  transform: translateX(100%);
}

.right-panel.active {
  transform: translateX(0);
}

.mask {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  z-index: 998;
}

.panel-content {
  position: relative;
  height: 100%;
  background: white;
  border-left: 1px solid #ebeef5;
  box-shadow: -2px 0 5px rgba(0, 0, 0, 0.05);
  display: flex;
  flex-direction: column;
}

.close-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1000;
  width: 30px;
  height: 30px;
}
</style>
